/**
 * @program: pettyloan
 * @ClassName CollectionController
 * @author: 汪江
 * @create: 2022-12-13 17:01
 **/
package com.wn.pettyloan.controller;

import com.wn.pettyloan.dto.CollectionDto;
import com.wn.pettyloan.entity.CollectionRecord;
import com.wn.pettyloan.entity.CollectionType;
import com.wn.pettyloan.service.CollectionRecordService;
import com.wn.pettyloan.service.CollectionTypeService;
import com.wn.pettyloan.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("collection")
public class CollectionController {
    @Resource
    private CollectionTypeService collectionTypeService;
    @Resource
    private CollectionRecordService collectionRecordService;
    @GetMapping("")
    public Result selAllCollectionType(){
        List<CollectionType> collectionTypes = collectionTypeService.selAllCollection();
        if (collectionTypes != null) {
            return Result.ok().data("list",collectionTypes);
        }else{
            return Result.error();
        }
    }
    @PostMapping("addRecord")
    public Result addRecord(@RequestBody CollectionDto collectionDto){
        System.out.println(collectionDto.toString());
        CollectionRecord collectionRecord = new CollectionRecord();
        collectionRecord.setRepayRecordId(collectionDto.getRepayRecord());
        collectionRecord.setCollectionDate(collectionDto.getCollectionDate());
        collectionRecord.setCollectionFeeback(collectionDto.getCollectionFeeback());
        collectionRecord.setRepayMoney(collectionDto.getRepayMoney());
        collectionRecord.setCollectionId(collectionDto.getCollectionType());
        int i = collectionRecordService.insertSelective(collectionRecord);
        if(i>0){
            return Result.ok();
        }else{
            return Result.error();
        }
    }


}
